<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of DataBaseClass
 *
 * @author Administrador
 */
class DataBaseClass {

    private $host;
    private $userName;
    private $password;
    private $db;
    private $connection;
    private $result;
    private $sql;
    public static $USUARIO = "tb_usuario";

    //put your code here
    function __construct($host, $userName, $password, $db) {
        $this->host = $host;
        $this->userName = $userName;
        $this->password = $password;
        $this->db = $db;
        $this->sql;
    }

    private function connectDB() {
        $this->connection = mysql_connect($this->host, $this->userName, $this->password);
        mysql_select_db($this->db);

        if (!$this->connection) {
            die('Não foi possível conectar: ' . mysql_error());
        }
    }

    public function setSPCDB() {
        $this->host = "localhost:3306";
        $this->userName = "root";
        $this->password = "9651myla";
        $this->db = "spc";
    }

    private function getResult() {
        return $this->result;
    }

    private function disconnect() {
        mysql_close($this->connection);
    }

    public static function SELECT_ONE_BY_ID($table, $codColumn, $value) {
        $db = new DataBaseClass();
        $db->setSPCDB();
        $result = $db->executeSQL("SELECT * FROM $table WHERE $codColumn=" . $value);
        $row = mysql_fetch_array($result, MYSQL_BOTH);
        return $row;
    }

    public function executeSQL($sql) {
        $this->connectDB();
        $this->result = mysql_query($sql, $this->connection);
        $this->disconnect();
        return $this->getResult();
    }

}
